package servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;

import entity.Ding;
import service.Ding_ser;



/**
 * Servlet implementation class Salzhuzhuangmap1
 */
@WebServlet("/Salzhuzhuangmap1")
public class Dingmap extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Dingmap() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setContentType("application/json");
		Ding_ser ds=new Ding_ser();	
		List<Ding> ding=ds.selectDingservice();
		Gson g = new Gson();
		Map<String, Object> map = new HashMap<>();
		for (Ding d1 : ding) {
			map.put("name", d1.getOid());
			map.put("data.json",d1.getNum());
		}
		String zl = g.toJson(map);
		PrintWriter out = response.getWriter();
		out.write(zl);
		out.close();		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
